# 带着二哈去旅行丶:ZZQ
# 生成时间：2021/12/6 下午10:27

import csv
import matplotlib.pyplot as plt
from datetime import datetime

filename = 'data/sitka_weather_2018_simple.csv'
with open(filename) as f1:
    reader = csv.reader(f1)
    header_row = next(reader)
    print('sitka_wearher')
    for index, column_header in enumerate(header_row):
        print(index, column_header)

    # 从文件中获取日期、最高温度和最低温度
    dates, highs1, lows1 = [], [], []
    for row in reader:
        current_date = datetime.strptime(row[2], '%Y-%m-%d')
        high = int(row[5])
        low = int(row[6])
        dates.append(current_date)
        highs1.append(high)
        lows1.append(low)

filename = 'data/death_valley_2018_simple.csv'
with open(filename) as f2:
    reader = csv.reader(f2)
    header_row = next(reader)
    print('death_valley')
    for index, column_header in enumerate(header_row):
        print(index, column_header)

    # 从文件中获取日期、最高温度和最低温度
    highs2, lows2 = [], []
    for row in reader:
        try:
            high = int(row[4])
            low = int(row[5])
        except ValueError:
            print(f"Missing data for {current_date}")
        else:
            highs2.append(high)
            lows2.append(low)

plt.style.use('Solarize_Light2')
fig, ax = plt.subplots(figsize=(10,6), dpi=128)
ax.plot(dates, highs1, c='red', label='sitka_high', linestyle='--') # label搭配ax.legend()添加图例 linestyle线的格式
ax.plot(dates, highs2, c='red', label='death_high')
ax.plot(dates, lows1, c='blue', label='sitka_low')
ax.plot(dates, lows2, c='blue', label='death_low')

ax.set_title('温度比较', fontsize=20)
ax.set_xlabel('', fontsize=16)
ax.set_ylabel('温度F', fontsize=16)
fig.autofmt_xdate()
ax.tick_params(axis='both', which='major', labelsize=16)
ax.legend()
plt.show()